<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
$getdata=$_REQUEST;
if(empty($getdata))$getdata=$_POST?$_POST:$_GET;
$type=empty($getdata['type'])?'':$getdata['type'];
$id=empty($getdata['id'])?'':$getdata['id'];
include("include/function.php");
//header("content-Type: application/json; charset=utf-8");
$config = include("config.php");
include("include/".$config['DB_TYPE'].".class.php");
$db = new db;
$db->connect($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD'],$config['DB_NAME'], $config['DB_PCONNECT']);
$sql = "select * from hema_school_class where uuid<>''";
$class = $db->get_all($sql);
$class_infos = [];
$school_infos = [];
foreach($class as $v){
    $class_infos[$v['uuid']]=$v;
    $school_infos[$v['school_uuid']]=$v;
}
$where="payed=2 and isMuslin=1";	
if($id){
    $where.=" and order_id>".$id;
}
$continues=[2158355,2159001,2159147,2159193,2159214,2159232,2159275,2159557,2160258,2160268,2160544,2160564,2160644,2160667,2160680,2160865,2160911,2161003,2161240,2161248,2161264,2161496,2161538,2161573,2161582,2161594,2161782,2161803,2161836,2162059,2162104,2162211,2162307,2162350,2162506,2162722,2162875,2162987,2163132,2163200,2163318,2163436,2163669,2163739,2163962,2164011,2164071,2164091,2164246,2164266,2164404,2164506,2164559,2164707,2164823,2164904,2165206,2165596,2165777,2166091,2166553,2166655,2166826,2166968,2167175,2167393,2167401,2167414,2167574,2167674,2168042,2168142,2168210,2168211,2168242,2168410,2168486,2168489,2168533,2168555,2168774,2168783,2168889,2168899,2169213,2169237,2169305,2169435,2169574,2169695,2169708,2169865,2169873,2169883,2169885,2170018,2170174,2170495,2170846,2170854,2170916,2170944,2171046,2171068,2171369,2171385,2171424,2171505,2171649,2171660,2171668,2172035,2172088,2172117,2172278,2172503,2172621,2172627,2172642,2172699,2172810,2172831,2172832,2172846,2172896,2173101,2173111,2173173,2173199,2173245,2173323,2173335,2173512,2173591,2173795,2173879,2174195,2174288,2174296,2174418,2174433,2174467,2174480,2174574,2174579,2174607,2174638,2174643,2174829,2174961,2175061,2175062,2175086,2175098,2175327,2175332,2175564,2175574,2175654,2175663,2175714,2175728,2175786,2175793,2175833,2175847,2175954,2176043,2176138,2176153,2176161,2176180,2176243,2176696,2176879,2176976,2177064,2177084,2177405,2177484,2177682,2177715,2177757,2177782,2177848,2177891,2177921,2178031,2178347,2178367,2178514,2178519,2178548,2178750,2178752,2178769,2178792,2178822,2178971,2179034,2179186,2179253,2179307,2179517,2179714,2180226,2180429,2180607,2180632,2180868,2180870,2181035,2181262,2181270,2181286,2181734,2181811,2181830,2181831,2181913,2181917,2182045,2182212,2182241,2182361,2182404,2182463,2182487,2183085,2183239,2183302,2183756,2185127,2183851,2183949,2183986,2184405,2184495,2184559,2184649,2184655,2184691,2184706,2184710,2184765,2184806,2184977,2185005,2185025,2185062,2185063,2185093,2185099,2185119,2185224,2185269,2185308,2185514,2185556,2185663,2185669,2185737,2185901,2186023,2186057,2186191,2186376,2186388,2186478,2186514,2186588,2186620,2186967,2186997,2187431,2187457,2187557,2187570,2187746,2187785,2188026,2188051,2188077,2188236,2188260,2188286,2188382,2188414,2188493,2188505,2188515,2188576,2188580,2188595,2188630
,2188651 ];
$sql = "select * from order_info where ".$where." order by id limit 1500";
$list = $db->get_all($sql);$insert=0;if(empty($list))exit('over');
$sqlarr=[];
foreach($list as $v){
    if($v['classId']){//学生
        $class_info=!empty($class_infos[$v['classId']])?$class_infos[$v['classId']]:'';
        if(empty($class_info)){
            print_r($v);exit;
        }else{
            $sql = "select student_id from hema_student where class_id ='".$class_info['class_id']."' and type=0 and status=1 and is_delete=0 and name='".$v['studentName']."'";
            $student_info = $db->get_one($sql);
            if(empty($student_info) && !in_array($v['id'],$continues)){
                $sql = "select student_id from hema_student where name='".$v['studentName']."'";
                if(!empty($school_infos[$v['unitid']]) && !empty($school_infos[$v['unitid']]['school_id']))$sql.=' and school_id='.$school_infos[$v['unitid']]['school_id'];
                $checkinfo = $db->get_one($sql);
                if(empty($checkinfo)){
                    $continues[]=$v['id'];
                }else{
                    echo implode(',',$continues);echo "\n<br>";
                    echo $sql."\n<br>";
                    echo $v['id']."\n<br>";
                    echo $v['unitName']."\n<br>";
                    echo $v['className']."\n<br>";
                    echo $v['parName']."\n<br>";
                    //print_r($v);
                    exit;
                }
                
                
            }
            $student_id=$student_info['student_id'];
            $sqlarr[]="update hema_student set is_qingzhen=1 where student_id=".$student_id.';';
        }
    }else{//教师
        $school_info=!empty($school_infos[$v['classId']])?$school_infos[$v['classId']]:'';
        if(empty($school_info)){
            print_r($v);exit;
        }else{
            
        }
    }
    
   /*$db->query("update hema_school_class set school_uuid='".$v['uuid']."' where school_id=".$v['school_id']);  */
}
//$log = $id.'导入成功,：'.$insert.'条';$page=0;
//echo $log.'<script>location.href="?page='.$page.'&id='.$id.'";</script>';

//echo count($sqlarr)."\n";
//echo implode(";\n",$sqlarr);
?>